<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@include file="../head.jsp"%>
<html>
<head>
<script type="text/javascript">
(function(){
    Ext.onReady(function(){
        Ext.QuickTips.init();

        var unitCombo = Ext.create('Ext.form.ComboBox',{
            id:'unit',
            name:'unit',
            queryMode:'local',
            editable:false,
            typeAhead:true,
            forceSelection: true,
            selectOnFocus: true,
            triggerAction:'all',
            displayField: 'label',
            valueField: 'value',
            width:100,
            allowBlank:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getUnit.action'
                },
                autoLoad: true
            })
        });

        var bgCombo = Ext.create('Ext.form.ComboBox',{
            fieldLabel:'报关方式',
            id:'flag',
            name:'flag',
            queryMode: 'local',
            typeAhead:true,
            forceSelection: true,
            selectOnFocus: true,
            triggerAction:'all',
            displayField: 'label',
            valueField: 'value',
            labelWidth: 80,
            width:350,
            allowBlank:false,
            editable:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getBg.action'
                },
                autoLoad: true
            })
        });

        var customerCombo = Ext.create('Ext.form.ComboBox',{
            fieldLabel:'委托方',
            id:'customerId',
            name:'customerId',
            editable:false,
            queryMode: 'local',
            displayField: 'label',
            typeAhead:true,
            valueField: 'value',
            labelWidth: 80,
            width:350,
            allowBlank:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getCustomer.action'
                },
                autoLoad: true
            })
        });

        var depotInType = Ext.create('Ext.form.ComboBox',{
            fieldLabel:'入库方式',
            id:'depotIn',
            name:'depotIn',
            editable:false,
            queryMode: 'local',
            displayField: 'label',
            typeAhead:true,
            valueField: 'value',
            labelWidth: 80,
            width:350,
            allowBlank:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getDepotInType.action'
                },
                autoLoad: true
            })
        });

        var contentCombo = Ext.create('Ext.form.ComboBox',{
            fieldLabel:'工作内容',
            id:'content',
            name:'content',
            editable:false,
            queryMode: 'local',
            displayField: 'label',
            typeAhead:true,
            valueField: 'value',
            labelWidth: 80,
            width:350,
            allowBlank:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getContent.action'
                },
                autoLoad: true
            })
        });

        var startAirport = Ext.create('Ext.form.ComboBox',{
            fieldLabel:'起始港',
            id:'startAirportId',
            name:'startAirportId',
            queryMode: 'local',
            displayField: 'label',
            typeAhead:true,
            valueField: 'value',
            forceSelection: true,
            selectOnFocus: true,
            triggerAction:'all',
            labelWidth: 80,
            width:350,
            allowBlank:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getAirport.action'
                },
                autoLoad: true
            })
        });

        var endAirport = Ext.create('Ext.form.ComboBox',{
            fieldLabel:'目的港',
            id:'endAirportId',
            name:'endAirportId',
            queryMode: 'local',
            typeAhead:true,
            forceSelection: true,
            selectOnFocus: true,
            triggerAction:'all',
            displayField: 'label',
            valueField: 'value',
            labelWidth: 80,
            width:350,
            allowBlank:false,
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getAirport.action'
                },
                autoLoad: true
            })
        });


        Ext.define('Employee', {
            extend: 'Ext.data.Model',
            fields: [
                { name: 'x', type: 'float' },
                { name: 'y', type: 'float' },
                { name: 'h', type: 'float' },
                { name: 'n', type: 'float' }
            ]
        });

        var store = Ext.create('Ext.data.Store', {
            model: 'Employee'
        });

        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            autoCancel: false
        });

        var grid = Ext.create('Ext.grid.Panel',{
            autoHeight:true,
            store:store,
            plugins: [rowEditing],
            columns:[
                {header:'长',dataIndex:'x',editor:{validator:floatCheck}},
                {header:'宽',dataIndex:'y',editor:{validator:floatCheck}},
                {header:'高',dataIndex:'h',editor:{validator:floatCheck}},
                {header:'数量',dataIndex:'n',editor:{validator:floatCheck}}
            ],
            tbar:[{
                text:'添加',
                iconCls:'create',
                handler:function(){
                    rowEditing.cancelEdit();
                    var add = Ext.ModelManager.create({
                        x:'1',
                        y:'1',
                        h:'1',
                        n:'1'
                    }, 'Employee');
                    store.insert(0, add);
                    rowEditing.startEdit(0, 0);
                }
            },{
                text:'删除',
                iconCls:'delete',
                id:'deleteButton',
                disabled:true,
                handler:function(){
                    var sm = grid.getSelectionModel();
                    rowEditing.cancelEdit();
                    store.remove(sm.getSelection());
                }
            }],
            listeners: {
                'selectionchange': function(view, records) {
                    Ext.getCmp('deleteButton').setDisabled(!records.length);
                }
            }
        });

        var window = Ext.create('Ext.window.Window', {
            title: '货物尺寸编辑',
            layout:'fit',
            closeAction:'hide',
            resizable:false,
            height:350,
            autoScroll:true,
            width:400,
            plain: true,
            modal:true,
            draggable:true,
            items:grid,
            buttons:[{
                text:'保存',
                handler:function(){
                    var sizeDesc = '';
                    store.each(function(record){
                        sizeDesc += record.get('x')+','+record.get('y')+','+record.get('h')+','+record.get('n')+';'
                    });
                    Ext.getCmp('sizeDesc').setValue(sizeDesc);
                    store.removeAll();
                    window.hide();
                }
            },{
                text:'取消',
                handler:function(){
                    window.hide();
                }
            }]
        });


        var form = Ext.create('Ext.form.Panel',{
            frame:true,
            title:'填写委托单信息',
            height:'100%',
            width:'100%',
            autoScroll:true,
            fieldDefaults: {
                labelAlign:'right',
                labelWidth: 80,
                width:350,
                allowBlank:false,
                maxLength:100
            },
            items:[{
                xtype:'fieldset',
                title:"基础信息",
                autoWidth:true,
                autoHeight:true,
                layout:{
                    type: 'table',
                    columns: 2
                },
                items:[contentCombo,customerCombo]
            },{
                xtype:'fieldset',
                title:"详细信息",
                autoWidth:true,
                autoHeight:true,
                layout:{
                    type: 'table',
                    columns: 2
                },
                defaultType: 'textfield',

                items:[startAirport,endAirport,{
                    fieldLabel:'货品名称',
                    id:'cargoName',
                    name:'cargoName',
                    width:700,
                    colspan:2
                },{
                    xtype: 'fieldcontainer',
                    fieldLabel: '数量',
                    combineErrors: true,
                    layout: 'hbox',
                    items:[{
                        xtype:'numberfield',
                        id:'num',
                        name:'num',
                        minValue:0,
                        width:160,
                        allowBlank:false
                    },unitCombo]
                },{
                    xtype: 'fieldcontainer',
                    fieldLabel: '尺寸描述',
                    combineErrors: true,
                    layout: 'hbox',
                    items:[{
                        xtype:'textfield',
                        readOnly:true,
                        id:'sizeDesc',
                        name:'sizeDesc',
                        width:205,
                        maxLength:500,
                        allowBlank:true
                    },{
                        xtype:'button',
                        text:'编辑描述',
                        handler:function(b,e){
                            window.show(b);
                        }
                    }]
                },{
                    fieldLabel:'体积',
                    xtype:'numberfield',
                    minValue:0,
                    id:'volume',
                    name:'volume',
                    allowBlank:false
                },{
                    fieldLabel:'重量',
                    xtype:'numberfield',
                    minValue:0,
                    id:'weight',
                    name:'weight',
                    allowBlank:false
                },{
                    fieldLabel:'希望的航班',
                    id:'flight',
                    name:'flight'
                },{
                    xtype:'datefield',
                    fieldLabel:'航班日期',
                    id:'flightDateStr',
                    name:'flightDateStr',
                    format:'Y-m-d'
                },depotInType,{
                    fieldLabel:'入库预计时间',
                    id:'depotInDesc',
                    name:'depotInDesc',
                    maxLength:300
                },bgCombo,{
                    xtype:'datefield',
                    fieldLabel:'报关日期',
                    format:'Y-m-d',
                    id:'bgDateStr',
                    name: 'bgDateStr',
                    allowBlank:true
                },{
                    fieldLabel:'<font color="red">所报运价</font>',
                    xtype:'numberfield',
                    minValue:0,
                    id:'price',
                    name:'price',
                    maxLength:10,
                    allowBlank:false
                },{
                    fieldLabel:'制单人',
                    id:'sysOperatorName',
                    name:'sysOperatorName',
                    readOnly:true,
                    allowBlank:true,
                    value:'<s:property value="#request.sysOperator" escape="false"/>',
                    maxLength:10
                },{
                    xtype:'textarea',
                    fieldLabel:'备注信息',
                    id:'remark',
                    name:'remark',
                    maxLength:500,
                    width:700,
                    allowBlank:true,
                    colspan:2
                }]
            }],
            renderTo:Ext.getBody(),
            buttonAlign:'center',
            buttons:[{
                text:'重置',
                handler:function(){
                    form.getForm().reset();
                }
            },{
                text:'提交',
                handler:function(){
                    if(!form.getForm().isValid()){
                        Ext.Msg.show({title:'提示',msg:'请填写必须项',icon:Ext.Msg.WARNING,buttons:Ext.Msg.OK});
                        return;
                    }
                    if(SysBase.isBlank(startAirport.getValue()) || SysBase.isBlank(endAirport.getValue())){
                        Ext.Msg.show({title:'提示',msg:'请正确选择起至港口',icon:Ext.Msg.WARNING,buttons:Ext.Msg.OK});
                        return;
                    }
                    var data = form.getForm().getValues();

                    form.getForm().submit({
                        url:'/fsxt/instruction/instruction!saveInstruction.action',
                        waitMsg: "正在提交,请稍候...",
                        waitTitle: "内容提交",
                        params:{data:encodeURIComponent(Ext.JSON.encode(data))},
                        success:function(){
                            Ext.Msg.show({title:'提示',msg:'保存数据成功!',icon:Ext.Msg.INFO,buttons:Ext.Msg.OK});
                            form.getForm().reset();
                        },
                        failure:function(){
                            Ext.Msg.show({title:'提示',msg:'[严重]:保存失败!',icon:Ext.Msg.ERROR,buttons:Ext.Msg.OK});
                        }
                    });

                }
            }]
        });

    });
})();
</script>
</head>
<body>
</body>
</html>